perm filename 106A17[1,RWF] blob sn#755238 filedate 1984-05-16 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	(for section on standard functions)
C00004 ENDMK
CāŠ—;
(for section on standard functions)

Exercise: (DIV and MOD) (or use as example?)

A bank represents the amounts of accounts, checks, deposits, etc., by integers,
using cents rather than dollars within the computer program. Design a procedure
to print such integers as dollar amounts in legible form; for example,
12345678 would be printed as $123,456.78, and 12 would be printed as $0.12.

Solution

	PROCEDURE DOLLARPRINT(CENTS:INTEGER)

	BEGIN
	COUNT:=2; POSITION:=100

	WHILE CENTS > 10*POSITION DO
		BEGIN
		POSITION:=10*POSITION;
		COUNT:=COUNT +1
		END
	WRITE ('$');
	FOR I:= COUNT DOWN TO 0 DO
		BEGIN
		WRITE(CENTS DIV POSITION:1);
		CENTS:=CENTS MOD POSITION;
		POSITION:=POSITION DIV 10;
		IF I=2 THEN WRITE ('.')
		ELSE IF I MOD 3=2 THEN WRITE (',')
		END
	END